﻿using System;
using System.IO;
using System.Linq;

namespace Fluffy.Archive.DragDropEngine
{
	internal class ZipStreamWrapper : Stream
	{
		private readonly ZipStream _source;
		private long _lenght;

		public ZipStreamWrapper(ZipStream source)
		{
			if (source == null) 
				throw new ArgumentNullException("source");

			_source = source;
		}

		public override void Flush()
		{
		}

		public override long Seek(long offset, SeekOrigin origin)
		{
			return 0;
		}

		public override void SetLength(long value)
		{
			_lenght = value;
		}

		public override int Read(byte[] buffer, int offset, int count)
		{
			return 0;
		}

		public override void Write(byte[] buffer, int offset, int count)
		{
			Position += count;
			_source.Add(buffer.Skip(offset).Take(count).ToArray(), Position == Length);
		}

		public override bool CanRead
		{
			get { return false; }
		}

		public override bool CanSeek
		{
			get { return false; }
		}

		public override bool CanWrite
		{
			get { return true; }
		}

		public override long Length
		{
			get { return _lenght; }
		}

		public override long Position { get; set; }
	}
}
